package com.zzy.system.service.impl;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.zzy.common.core.redis.RedisCache;
import com.zzy.system.domain.PurchaseOrder;
import com.zzy.system.domain.PurchaseOrderDetail;
import com.zzy.system.domain.PurchaseOrderDetailItem;
import com.zzy.system.mapper.PurchaseOrderDetailItemMapper;
import com.zzy.system.mapper.PurchaseOrderDetailMapper;
import com.zzy.system.mapper.PurchaseOrderMapper;
import com.zzy.system.service.IPurchaseOrderDetailService;
import com.zzy.system.service.IPurchaseOrderDetailitemService;
import com.zzy.system.service.IPurchaseOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
public class PurchaseOrderDetailitemServiceImpl extends ServiceImpl<PurchaseOrderDetailItemMapper, PurchaseOrderDetailItem> implements IPurchaseOrderDetailitemService {
    private static final Logger log = LoggerFactory.getLogger(PurchaseOrderDetailitemServiceImpl.class);

    @Override
    public void saveBatchList(List<PurchaseOrderDetailItem> purchaseOrderDetailItemList) {
        if(!purchaseOrderDetailItemList.isEmpty()){
            QueryWrapper<PurchaseOrderDetailItem> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("purchase_sheet_id", purchaseOrderDetailItemList.get(0).getPurchaseSheetId());
            baseMapper.delete(queryWrapper);
            this.saveBatch(purchaseOrderDetailItemList);
        }


    }
}